const webpack = require('webpack');
const appBuildInfos = require('./build-info-processing');
const commons = require('./webpack.common');
const { production } = require('./build-config');


const sequentiallyBuild = async () => {
    for (let i = 0; i < appBuildInfos.length; i++) {
        const info = appBuildInfos[i];
        console.log('Current build information:', info);
        const config = production(commons[i], info);

        const compiler = webpack(config);
        await new Promise((resolve, reason) => {
            compiler.run((err, result) => {
                if (err) {
                    console.error('Failed to build project:', info.name, err);
                    reason(err);
                } else {
                    console.log('Successfully built project:', info.name);
                    resolve(result);
                }
            });
        });
    }
};

sequentiallyBuild().then((value) => {
    console.log('All projects built successfully!');
}, (err) => {
    console.error('Build failed:', err);
});